//
//  CBattleObject.h
//  Monster_Martial_Arts_Version_0
//
//  Created by chiawei.tseng on 13/1/7.
//
//

#ifndef Monster_Martial_Arts_Version_0_CBattleObject_h
#define Monster_Martial_Arts_Version_0_CBattleObject_h

#include "CObject.h"
#include "point.h"
#include "CArmature.h"
//#include "CAnimationSystem.h"
#include "GameDef.h"
//#include "CActiveAnimation.h"
#include "CAIManager.h"

using namespace MMA;

class CCArmature;
class CCArmatureAnimation;
class CAnimationSystem;
class CBaseCommand;
class CCallBack;
class CBattleObject : public CObject 
{
    friend class CAnimationSystem;
public:
    
    struct BATTLEOBJECT_STATE
    {
        
    };
    
    struct BATTLEOBJECT_BASE_DATA : public OBJECT_DATA
    {
        fPoint m_fpoint;
        
        BATTLE_TEAM_NUMBER m_teamNamber;
    };
    
    template<typename T>
    inline  static               CBattleObject*    CreateObject(CCNode* ,const char* , fPoint);
    
    CBattleObject();
    
    virtual                      ~CBattleObject(){}
    
    virtual bool                 Init(CCNode* , fPoint);
    
    bool                         InitWithData(const char* , CCNode*);
    
    virtual void                 Update(CCNode* , float dTime);
    
    virtual void                 Release(CCNode*);
    
    void                         ChangeActiveAnimation(ACTIVE_ANIMATION_ID AnimationID);
    
    ACTIVE_ANIMATION_ID          GetCurrActiveAnimation();//{return m_pAnimationSys->GetCurrActiveAnimation();}
    
    inline  BATTLE_OBJECT_STATE  GetBattleObjectState();
    
    inline  bool                 isDie();
    
    inline  fPoint&              GetPoint();
    
    inline  BATTLE_TEAM_NUMBER   GetTeamNumber();
    
    inline  void                 SetTeamNumber(BATTLE_TEAM_NUMBER);
    
    bool                         isAABB(const fPoint&);
    
    void                         processCommand(CBaseCommand*);
    
    void                         RegisterAnimationCallBack(ACTIVE_ANIMATION_ID,CCallBack*);
    
protected:
    
    void                         processSprite(CCNode*);
    
    BATTLEOBJECT_BASE_DATA       m_BattleData;
    
    BATTLE_OBJECT_STATE          m_BattleState;
    
    CCArmature*                  m_pArmature;
    
    CAnimationSystem*            m_pAnimationSys;
    
    CAIManager*                  m_pAiManager;
    
private:
    
    void                         PlayToAnimation(const char*);
    
    void                         UpdateAnimation(float dTime);
    
    void                         RegisterAniEventListen(CCAnimationEventListener*);
    
    
};

bool CBattleObject::isDie()
{
    return m_BattleData.nHP <= 0;
}

fPoint& CBattleObject::GetPoint()
{
    return m_BattleData.m_fpoint;
}

BATTLE_OBJECT_STATE CBattleObject::GetBattleObjectState()
{
    //return m_BattleState;
    return static_cast<BATTLE_OBJECT_STATE>(m_pAiManager->GetCurrentStateID());
}

BATTLE_TEAM_NUMBER   CBattleObject::GetTeamNumber()
{
    return m_BattleData.m_teamNamber;
}

void CBattleObject::SetTeamNumber(BATTLE_TEAM_NUMBER number)
{
    m_BattleData.m_teamNamber = number;
}

template<typename T>
CBattleObject*  CBattleObject::CreateObject(CCNode* pNode,const char* Name, fPoint Point)
{
    CBattleObject* object = new T();
    
    if (object && object->InitWithData(Name,pNode))
    {
        object->Init(pNode, Point);
        
        return object;
    }
    
    return NULL;
    
}

#endif
